/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aptech.bluepumpkin;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

        

/**
 *
 * @author Trong Nguyen
 */
@Entity
@Table(name = "Prize")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Prize.findAll", query = "SELECT p FROM Prize p ORDER BY p.id DESC"),
    @NamedQuery(name = "Prize.findById", query = "SELECT p FROM Prize p WHERE p.id = :id"),
    @NamedQuery(name = "Prize.findByTitle", query = "SELECT p FROM Prize p WHERE p.title = :title"),
    @NamedQuery(name = "Prize.findByCreatedDate", query = "SELECT p FROM Prize p WHERE p.createdDate = :createdDate"),
    @NamedQuery(name = "Prize.findByCreatedBy", query = "SELECT p FROM Prize p WHERE p.createdBy = :createdBy")})
public class Prize implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
  @GeneratedValue(strategy = GenerationType.IDENTITY) 
    @Column(name = "id")
    private Integer id;
    @Size(max = 250)
    @Column(name = "title")
    private String title;
    @Lob
    @Size(max = 2147483647)
    @Column(name = "contents")
    private String contents;
    @Column(name = "createdDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdDate;
    @Column(name = "createdBy")
    private Integer createdBy=0;// NOT USE
    @JoinColumn(name = "event", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Event event;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "prize")
    private List<Winner> winnerList;

    public Prize() {
    }

    public Prize(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTitle() {
       return title; 
    }
    public void setTitle(String title) {
        this.title = title;
    }

    public String getContents() {
       
     return  contents;
    }

    public void setContents(String contents) {
        this.contents = contents;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public Integer getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(Integer createdBy) {
        this.createdBy = createdBy;
    }

    public Event getEvent() {
        return event;
    }

    public void setEvent(Event event) {
        this.event = event;
    }

    @XmlTransient
    public List<Winner> getWinnerList() {
        return winnerList;
    }

    public void setWinnerList(List<Winner> winnerList) {
        this.winnerList = winnerList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Prize)) {
            return false;
        }
        Prize other = (Prize) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.aptech.bluepumpkin.Prize[ id=" + id + " ]";
    }
    
}
